$(function(){
	goToPage(1);
	$('.close').click(function(){
		$('.regsuc_cjcd_box').hide(10);
		$('.login_main').hide(10);
	});
});
function joinCompany(){
	$("#joinCompany").show();
	$("#createCompany").hide();
}
function createCompany(){
	$("#createCompany").show();
	$("#joinCompany").hide();
}
function cheacin(companyId){
	$.ajax({
		url : contextPath+ 'user/companyuser/cheacin',
		data : {
			companyId : companyId
		},
		type : 'POST',
		success : function(data) {
			alert(data.msgDesc);
			location.reload();
		}
	});
}
function delcompany(companyId){
	$.ajax({
		url : contextPath+'user/company/del',
		data : {
			companyId : companyId
		},
		type : 'POST',
		success : function(data){
			alert(data.msgDesc);
			goToPage(1);
		}
	});
}
function goToPage(pageNo){
	$.ajax({
		url : contextPath+ 'user/company/mycompany',
		data : {
			pageNo : pageNo,
			pageSize:10
		},
		type : 'POST',
		success : function(list) {
			$("#content").empty();
			$(".page").empty();
			if(list!=null && list.totalRecord>0){
				var objlist = list.records;
				for(var i=0;i<objlist.length;i++){
					var div = '<div class="pwsj_right_czrz_cont">';
					div += '<ul class="czrz_cont_ul">';
					div += '<li class="number" style="width: 5%">'+(i+1)+'</li>';
					div += '<li class="number" style="width: 8%">'+objlist[i].companyId+'</li>';
					div += '<li class="time" style="width: 23%">'+objlist[i].companyName+'</li>';
					div += '<li class="operation" style="width: 20%">'+objlist[i].address+'</li>';
					div += '<li class="username" style="width: 20%">'+(objlist[i].parentCompanyName==null?"":objlist[i].parentCompanyName)+'</li>';
					if(companyid!=objlist[i].companyId){
						div += '<li class="username" style="width: 21%;border-right:none;"><a onclick="cheacin('+objlist[i].companyId+');" >进入该单位</a>';
						if(userId==objlist[i].creatorId){
							div += '<a onclick="delcompany('+objlist[i].companyId+');"  style="margin-left:10px">删除单位</a>';
						}
					}else{
						div += '<li class="username" style="width: 22%;border-right:none;"><a href="'+contextPath+'user/m/currentcompany.jsp">当前单位</a>';
					}
					div +='</li>';
					div += '</ul>';
					div += '</div>';
					$("#content").append(div);
				}
				pageList(list);
			}
		}
	});
}

